import {ADD_CART,ADD_COUNTER} from "./mutation-types";

export default {
  addCart(context, payload) {
    return new Promise(resolve => {
      let oldProduct = context.state.cartList.find(item => payload.iid === item.iid)

      if (oldProduct) {
        context.commit(ADD_COUNTER, oldProduct)
        resolve('商品数量加1')
      } else {
        payload.count = 1
        context.commit(ADD_CART,payload)
        resolve('商品成功添加到购物车')
      }
    })
  }
}
